package org.example.wikwok.pojo;

import org.example.wikwok.common.ReturnedMessage;

import java.io.Serial;
import java.io.Serializable;

public class Result<T> implements Serializable {

    @Serial
    private static final long serialVersionUID = 1L;
    private boolean success;
    /**返回消息**/
    private String message;

    /**返回数据**/
    private T data;

    private Result(){}
    public static <T> Result<T> ok(T data,int code) {

        Result<T> response = new Result<>();
        response.setSuccess(true);
        response.setMessage(ReturnedMessage.getMessages(code));
        response.setData(data);
        return response;
    }

    /**
     * 编译失败方法
     */
    public static <T> Result<T> buildFailure(int code){

        Result<T> response = new Result<>();
        response.setSuccess(false);
        response.setMessage(ReturnedMessage.getMessages(code));
        return response;
    }




    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public boolean isSuccess() {
        return success;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }



}
